/**
 * Created by Baggio on 2018-9-26.
 */
$(function () {
    $(".state").find("span").click(function () {
        var status = $(this).attr("data");
        var orderId = $(this).parent(".state").siblings(".title_01").find(".order_n").html();
        /*    if(status<13){
         return;
         }*/

        if (status == 13) {
            $(this).parent(".state").siblings(".show").show();
            getAddress(orderId);
            getLogistics(orderId);
        }
        if (status == 2 || status == 16|| status == 17) {
            var timestamp = Date.parse(new Date());
            location.href = "https://www.showcai.com/pay/payResult.html?orderId=" + orderId+"&v="+timestamp;

        }
  if (status == 1) {
            var timestamp = Date.parse(new Date());
            location.href = "https://www.showcai.com/pay/pay/"+orderId+".html?v="+timestamp;

        }


    });
    // $(".show").show();
});
function getAddress(orderId) {
    var postData = {"orderId": orderId};
    $.ajax({
        url: "/apply/getApplyWatchById.html",
        type: "post",
        dataType: "json",
        data: postData,
        beforeSend: function () {

        },//执行ajax前执行loading函数.直到success
        success: function (res) {
            console.log(res);
            if (res.code != 1) {
                alert(res.msg);
                return;
            }
            $(".span_3").html("<span><img src=\"\" alt=\"\"></span> " + res.data.name + " <span class=\"span_3\">" + res.data.phone + "</span>");
            $(".address").html(res.data.address);
        },
        complete: function () {
        }
    });
}
function getLogistics(orderId) {
    var postData = {"orderId": orderId};
    $.ajax({
        url: "/expressInfo/getExpressInfoByOrderId.html",
        type: "post",
        dataType: "json",
        data: postData,
        beforeSend: function () {


        },//执行ajax前执行loading函数.直到success
        success: function (res) {
            console.log(res);
            if (res.code != 1) {
                alert(res.msg);
                return;
            }

            var html = "";
            var datas = JSON.parse(res.data);
            $(".logistics_number").html(datas.LogisticCode);

            var ShipperCode = datas.LogisticCode == "ZTO" ? "中通快递" : datas.LogisticCode == "YTO" ? "圆通速递" : datas.LogisticCode == "STO" ? "申通快递" : datas.LogisticCode == "YD" ? "韵达速递" : "";
            $(".logistics_companycompany").html(ShipperCode);
            var traces = datas.Traces;
            for (var i = 0; i < traces.length; i++) {
                html += "    <div class=\"detailed\">";
                html += "    <div class=\"time_01\">";
                html += "      <span>" + traces[i].AcceptTime.split(" ")[0] + "<br>" + traces[i].AcceptTime.split(" ")[1] + "</span>";
                html += "     </div>";
                html += "    <div class=\"seat\">";
                html += traces[i].AcceptStation
                html += "    </div>"
                html += "    </div>"
            }
            $(".list_fast").html(html);
        },
        complete: function () {

        }
    });
}